function batchCandE(inDir,outDir)


filter=fullfile(inDir,'*beta*.mat');
files=dir(filter);
nSurr=100;
for i=1:length(files)
    fileName=files(i).name;
    info=whos('-file',fullfile(inDir,fileName));
    varName=info.name;
    load(fullfile(inDir,fileName),varName);
    nSubjs=size(eval(varName),1);
    
    c=zeros(nSubjs,1);
    e=zeros(nSubjs,1);
    c_w=zeros(nSubjs,1);
    e_w=zeros(nSubjs,1);
    sw=zeros(nSubjs,1);
    for j=1:nSubjs
        m=squeeze(eval(strcat(varName,'(j,:,:)')));
        [c(j),e(j)]=graphMeasure(m);
        [c_w(j),e_w(j)]=surrogateNet(m,nSurr); 
    end

     if(all((c./c_w)>1))
        sw=(c./c_w)./((e./e_w));   
     end    
      
    
    outfile=strcat('ce_',fileName);
    save(fullfile(outDir,outfile),'c','e','c_w','e_w','sw');
end

function [c_w,e_w]=surrogateNet(m,nSurr)

c=zeros(nSurr,1);
e=zeros(nSurr,1);
for i=1:nSurr
    %rw=null_model_und_sign(m,1);
    rw=randWeightedGraph(m);
    [c(i),e(i)]=graphMeasure(rw);
end
c_w=mean(c);
e_w=mean(e);


function [connectionM]=randWeightedGraph(connectionM)

nCh=length(connectionM);

for i=1:nCh
    for j=i+1:nCh
        a=randi(nCh-1,1);
        b=1;
        tel=0;
        
        while(b<=a && tel<1000)
            tel=tel+1;
            b=randi(nCh,1);
        end
        
        old=connectionM(i,j);
        connectionM(i,j)=connectionM(a,b);
        connectionM(a,b)=old;
        
        old=connectionM(j,i);
        connectionM(j,i)=connectionM(b,a);
        connectionM(b,a)=old;
       
    
    end

end